package servlet;


import com.alibaba.fastjson.JSONObject;
import service.schooltreasure_teacherService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "dengluServlet", value = "/dengluServlet")

public class dengluServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


    }
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        resp.setContentType("text/html;charset=UTF-8");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");

        String userName = (req.getParameter("userName"));
        int password = (Integer.parseInt(req.getParameter("password")));
        schooltreasure_teacherService schooltreasure_teacherService = new schooltreasure_teacherService();

        int x=-1;


        try {
            x = schooltreasure_teacherService.denglu(userName,password);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        PrintWriter PrintWriter = resp.getWriter();

        if (x>=0) {
            PrintWriter.print("<script> window.location='user.html?"+userName+"&"+x+"' </script>");
        } else {
            PrintWriter.print("<script>alert('登录失败！'); window.location='login.html' </script>");

        }
        PrintWriter.flush();
        PrintWriter.close();
    }
    }